#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int compareVersion(string& version1, string& version2) {
        int i = 0, j = 0;
        int n = version1.size(), m = version2.size();
        while (i < n || j < m)
        {
            int a = 0, b = 0;
            while (i < n && version1[i] != '.')
            {
                a *= 10;
                a += version1[i] - '0';
                i++;
            }
            while (j < m && version2[j] != '.')
            {
                b *= 10;
                b += version2[j] - '0';
                j++;
            }
            if (a < b) return -1;
            else if (a > b) return 1;
            ++i; ++j;
        }
        return 0;
    }
};